<template>
   <table>
    <tr>
        <td>用户名:</td>
        <td>
            <input type="text"  v-model="name" placeholder="请输入用户名">
        </td>
    </tr> 
    <tr>
        <td>密码:</td>
        <td>
            <input type="password" v-model="password" placeholder="请输入密码">
        </td>
    </tr> <tr>
        <td></td>
        <td>
            <input type="button" value="登录"  @click="log">
        </td>
    </tr>
   </table>
</template>

<script setup lang="ts">
import {onMounted,ref} from 'vue'
import { useRoute,useRouter } from 'vue-router';
import axios from 'axios'
import {useCounterStore} from '../../stores/counter.ts'

const userstore=useCounterStore();
const name=ref("")
const password=ref("")
const user=useRouter();
const log=()=>{
    if(name.value=="")
    {
        alert("用户名不能为空");
        return;
    }
    if(password.value=="")
    {
        alert("密码不能为空");
        return;
    }
    axios.get("https://localhost:7234/api/RoomInfo/GetUserBylog",{
        params:{
            name:name.value,
            pwd:password.value
        }
    })
    .then(res=>{
        console.log(res);
     if(res.data.Coid==3){
        alert(res.data.Msg)
        userstore.username=res.data.Data_info.U_Name
        alert(userstore.username);
        user.push("/AddRoomInfo")
     }else if(res.data.Coid==-2){
        alert(res.data.Msg)
     }else if(res.data.Coid==-1){
        alert(res.data.Msg)
     }
     
    })

}
</script>

<style scoped>

</style>